package com.ch.demo;

import java.lang.annotation.*;
import java.lang.reflect.Field;

@DemoAnno(value = "demo2",nums = 19)
public class Demo3 {
    @DemoAnno(value = "",nums = 1)
    public String name;

    @DemoAnno(value = "11",age = "18",nums = {1,2})
    public void test(){

    }

    public static void main(String[] args) throws NoSuchFieldException {
        Field name = Demo3.class.getDeclaredField("name");
        DemoAnno annotation = name.getAnnotation(DemoAnno.class);
        System.out.println("annotation.value() = " + annotation.value());

        Demo4 demo4 = new Demo4();

        Class<? extends Demo4> aClass = demo4.getClass();
        DemoAnno annotation1 = aClass.getAnnotation(DemoAnno.class);
        System.out.println("annotation1.value() = " + annotation1.value());

    }
}
class Demo4 extends Demo3 {

}
@Target(
        value = {
                ElementType.METHOD
                ,ElementType.FIELD
                ,ElementType.TYPE}
)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface DemoAnno{
    String value();
    String age() default  "1";
    int[] nums();
}